﻿using Stu_sys.Models;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using System.Text.Json;

namespace Stu_sys.utils
{
    public static class MyUtils
    {
        public static string GetAttributeToJsonStr(Type t) 
        {
            //string attrs = "";
            List<string> list = new List<string>();
            var type = t;
            foreach (var item in type.GetProperties())
            {
                foreach (var attr in item.GetCustomAttributes<DisplayAttribute>())
                {
                    //attrs += attr.Name + " ";
                    list.Add(attr.Name);
                }
            }
            //var res = attrs.Trim().Split(" ");
            var attrStr = JsonSerializer.Serialize(list);
            return attrStr;
        }
    }
}
